a = input()
if len(a) == 4:
    v1, v2, v3, v4 = a[0], a[1], a[2], a[3]
    f = [int(v1), int(v2), int(v3), int(v4), int(v1 + v2), int(v3 + v4), int(v1 + v2 + v3), int(v2 + v3 + v4), int(v1 + v2 + v3 + v4)]
    b = 0
    e = []
    for c in f:
        b = 0
        for d in range(2, c - 1):
            if c % d == 0:
                b = 1
        if b == 0:
            e.append(c)
        else:
            print(0)
if len(e) > 0:
    print(max(e))
else:
    print(0)
